package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.pb.union.cross.CrossUnionProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = Protocol.S_UNION_CONSTRUCT_ACTIVE_REWARD_FROM_CROSS, desc = "领取建设活跃度奖励")
public class GetConstructActiveRewardCmdFromCross extends AbstractCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        CrossUnionProto.UnionConstructActiveRewardCrossRespMsg respMsg = CrossUnionProto.UnionConstructActiveRewardCrossRespMsg.parseFrom(packet.getBytes());
        if(respMsg.hasReward()){
            if(!StringUtils.isNullOrEmpty(respMsg.getReward())){
                Property reward = PropertyHelper.parseStringToProperty(respMsg.getReward());
                if (null != reward) {
                    player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.Union, eLogMoneyType.UnionConstructActive);
                }
            }
        }
        UnionProto.UnionConstructActiveRewardRespMsg.Builder clientMsg = UnionProto.UnionConstructActiveRewardRespMsg.newBuilder();
        clientMsg.setRet(ret);
        clientMsg.addAllActiveIndex(respMsg.getActiveIndexList());
        player.sendPacket(Protocol.U_UNION_CONSTRUCT_ACTIVE_REWARD, clientMsg);

    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
